package One;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

public class Project {

    /*创建项目类，属性有项目名称，项目开始日期，项目结束日期。生成get/set方法。
    提供计算工期的get方法。完成工期的计算（项目开始日期和项目结束日期间隔天数）
    提供计算剩余天数的get方法。完成剩余天数的计算（当前时间和项目结束日期间隔天数）
    重写toString()方法，要求返回项目名、项目工期、项目剩余天数
     */

    private String projName;
    private String beginTime;
    private String overTime;

    public Project(String projName, String beginTime, String overTime) {
        this.projName = projName;
        this.beginTime = beginTime;
        this.overTime = overTime;
    }

    public String getProjName() {
        return projName;
    }

    public void setProjName(String projName) {
        this.projName = projName;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getOverTime() {
        return overTime;
    }

    public void setOverTime(String overTime) {
        this.overTime = overTime;
    }




    public long workPeriod(String aTime,String bTime){
        String[] info = aTime.split("-");
        String[] info1 = bTime.split("-");
        int beginYear = Integer.parseInt(info[0]);
        int beginMonth = Integer.parseInt(info[1]);
        int beginDay = Integer.parseInt(info[2]);
        int overYear = Integer.parseInt(info1[0]);
        int overMonth = Integer.parseInt(info1[1]);
        int overDay = Integer.parseInt(info1[2]);

        return ChronoUnit.DAYS.between(LocalDate.of(beginYear,beginMonth,beginDay),LocalDate.of(overYear,overMonth,overDay));
    }

    public long overPeriod(String bTime){
        String[] info1 = bTime.split("-");
        int overYear = Integer.parseInt(info1[0]);
        int overMonth = Integer.parseInt(info1[1]);
        int overDay = Integer.parseInt(info1[2]);

        return ChronoUnit.DAYS.between(LocalDate.now(),LocalDate.of(overYear,overMonth,overDay));
    }

    @Override
    public String toString() {
        return "Project{" +
                "projName='" + projName + '\'' +
                ", beginTime='" + beginTime + '\'' +
                ", overTime='" + overTime + '\'' +
                '}';
    }
}
